//
//  Global.m
//  FrogDrying
//
//  Created by Le Thanh Hai on 4/2/13.
//
//

#import "Global.h"
#import "KeychainItemWrapper.h"
#import "UIApplication+UIID.h"
#import "NSUserDefaults+MPSecureUserDefaults.h"
#import "Reachability.h"
#import "SimpleAudioEngine.h"
#import "CCMenuItem.h"

@implementation UIButton (FIX)

- (void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
{
    [[SimpleAudioEngine sharedEngine] playEffect:@"click.mp3"];
}

@end

@implementation Global

+(void)setScore:(NSInteger)score
{
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    [prefs setSecureInteger:score forKey:@"597db17fa0aa829cf9f3cb052af96183"];
    
    int heightScore = [Global getHeightestScore];
    if (heightScore < score) {
        [prefs setSecureInteger:score forKey:@"51b17829cf9f3cb97d052afa0aaf9683"];
    }
}

+(NSInteger)getHeightestScore
{
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    BOOL valid = NO;
    int bestScore = [prefs secureIntegerForKey:@"51b17829cf9f3cb97d052afa0aaf9683" valid:&valid];
    if (!valid) {
        [prefs setSecureInteger:0 forKey:@"51b17829cf9f3cb97d052afa0aaf9683"];
        return 0;
    } else {
        return bestScore;
    }
    return bestScore;
}

+(NSInteger)getLastestScore
{
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    BOOL valid = NO;
    int lastestScore = [prefs secureIntegerForKey:@"597db17fa0aa829cf9f3cb052af96183" valid:&valid];
    if (!valid) {
        [prefs setSecureInteger:0 forKey:@"597db17fa0aa829cf9f3cb052af96183"];
        return 0;
    } else {
        return lastestScore;
    }
    return lastestScore;
}


+ (BOOL)checkNetworkAvailable
{
    Reachability* wifiReach = [Reachability reachabilityForInternetConnection];
    
    NetworkStatus netStatus = [wifiReach currentReachabilityStatus];
    
    if (netStatus == NotReachable) {
        return NO;
    }
    return YES;
}
@end
